Skip to main content
ICT
Lesson A7 - Simple I/O
 
Main Previous
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

LAB ASSIGNMENT A7.1 page 7 of 7

GroceryList

Background:

Young college students who are living alone for the first time often find grocery shopping to be one of the biggest pains. Besides the simple fact that they are busy and don’t have time to go to the store, it is often difficult to add up and calculate how much money is needed to buy everything that has been put into the shopping cart. This program will help to simplify that problem.

Assignment:

You will write a program that will accept a list of 5 grocery items along with their prices. The program should calculate the total cost of the items on a line-by-line basis and format the output so it looks clean and even.

Instructions:

  1. Prompt the user for the cost of item #1.

  2. Repeat step # 1 four additional times.

  3. When you have accepted all the values, print them to the screen with a total value printed next to them. Make sure everything is straight and aligned.

  4. Here is a sample run:

    Enter item #1: 2.59
    Enter item #2: 5.25
    Enter item #3: 6.34
    Enter item #4: 4.50
    Enter item #5: 8.72

  5. Set all your width specifications to 10 and all your precision to 2, where appropriate. Instead of using any regular spaces to align your columns, only use the printf method. Use the println method only for changing lines.

 

Main Previous
Contact
 © ICT 2006, All Rights Reserved.